<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>基础信息设置</title>
    <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/static/assets/module/admin.css?v=312" />
    <style>
        .layui-form-item {
            margin-bottom: 25px;
        }

        label .layui-icon {
            font-size: 14px;
            color: #666;
        }
    </style>
</head>

<body>
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" style="max-width: 700px;margin: 40px auto;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题:</label>
                        <div class="layui-input-block">
                            <textarea type="text" name="title" placeholder="" class="layui-textarea"
                                lay-verify="required" required></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选项:</label>
                        <div class="layui-input-block">
                            <textarea type="text" id="option" name="option" placeholder="" class="layui-textarea"
                                lay-verify="required" required></textarea>
                            <div class="layui-form-mid layui-word-aux">直接回车换行即可，自动替换Html换行格式</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">答案:</label>
                        <div class="layui-input-block">
                            <input type="text" name="answer" placeholder="" class="layui-input" lay-verType="tips"
                                lay-verify="required" value="" required />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">价格:</label>
                        <div class="layui-input-block">
                            <input type="number" name="price" placeholder="" class="layui-input" lay-verType="tips"
                                lay-verify="required" value="" required />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类:</label>
                        <div class="layui-input-block">
                            <select name="type" lay-verify="required">
                                {volist name="sort" id="vo"}
                                <option value="{$vo.Id}">{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-filter="formSubmitBas" lay-submit>&emsp;提交&emsp;</button>
                            <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- js部分 -->
    <script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
    <script type="text/javascript" src="/static/assets/js/common.js?v=312"></script>
    <script>
        layui.use(['layer', 'form', 'element', 'laydate'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var element = layui.element;
            // 监听表单提交
            form.on('submit(formSubmitBas)', function (data) {
                var txt = data.field.option;
                txt = txt.replace(/\r\n/g, "</br>");
                txt = txt.replace(/\n/g, "</br>");
                data.field.option = txt;
                $.ajax({
                    type: "POST",
                    url: "{:url('admin/question/add_question')}",
                    data: data.field,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 0) {
                            layer.alert(data.msg, {
                                end: function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                }
                            }
                            );
                        }else if(data.code == 3){
                            layer.alert(data.msg);
                        } else {
                            layer.alert(data.msg);
                        }
                    },
                    error: function (data) {
                        alert("请求失败");
                    }
                });

                return false;
            });

        });
    </script>
</body>

</html>